package club.zhilin.guli.service.edu.controller.portal;

import club.zhilin.guli.common.base.result.CommonResult;
import club.zhilin.guli.service.edu.domain.Teacher;
import club.zhilin.guli.service.edu.service.ITeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zhilin
 * @since 2022/2/14 19:01
 */
@Api(tags = "讲师管理")
@RestController
@RequestMapping("/portal/edu/teacher")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PortalTeacherController {

    private final ITeacherService iTeacherService;

    @ApiOperation("查询讲师列表")
    @GetMapping("/list")
    public CommonResult<List<Teacher>> list() {
        List<Teacher> list = iTeacherService.list();
        return CommonResult.success("获取讲师列表成功", list);
    }

    @ApiOperation("通过id查询讲师")
    @GetMapping("/teacher/{id}")
    public CommonResult<Teacher> teacher(@PathVariable String id) {
        Teacher teacher = iTeacherService.getById(id);
        return teacher == null ? CommonResult.failed("未查询到该信息") : CommonResult.success(teacher);
    }

    @ApiOperation("通过讲师id查询改讲师所授的所有课程")
    @GetMapping("/course/{teacherId}")
    public CommonResult<Map<String, Object>> course(@PathVariable String teacherId) {
        return CommonResult.success(iTeacherService.selectCourseByTeacherId(teacherId));
    }
}
